package com.rss;

import java.net.MalformedURLException;
import java.net.URL;
import com.rss.alerta;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class editorURL extends Activity {
	EditText mText;

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		
		setContentView(R.layout.editor_url);

		// Set up click handlers for the text field and button
		mText = (EditText) this.findViewById(R.id.url);

		if (icicle != null)
			mText.setText(icicle.getString("url"));

		Button ok = (Button) findViewById(R.id.ok);
		ok.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				okClicked();
			}
		});

		Button cancel = (Button) findViewById(R.id.cancel);
		cancel.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				finish();
			}
		});

	}

	protected void okClicked() {
    	try {
    		RssManejador rh = new RssManejador();
       		rh.crearFeed(this, new URL(mText.getText().toString()));
    		finish();
    	} catch (MalformedURLException e) {
    		alerta.mostrarAlerta(this, "Error URL", "Ha introducido una URL inválida", "OK");
    		Log.e("falla onclick", e.toString());
    	}
    }

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putString("url", mText.getText().toString());
	}
	
	


}
